package com.yuchen.utils.springmvc;



import com.yuchen.utils.XssUtils;


import java.beans.PropertyEditorSupport;

/**
 * Created with IntelliJ IDEA.
 * User: qintao
 * Date: 13-6-17
 * Time: 下午1:17
 *javascript XSS属性编辑器
 */
public class XssEditorSupport extends PropertyEditorSupport {

    public XssEditorSupport() {
        super();
    }

    @Override
    public void setAsText(String text) {
        if (null==text || text.equals("")) {
            setValue(null);
        } else {
            String value = text;
            setValue(XssUtils.htmlspecialchars(text));
        }
    }

    @Override
    public String getAsText() {
        Object value = getValue();
        return value != null ? value.toString() : "";
    }

}
